﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetMembersInfo : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            MembersInfoOutParam result = new MembersInfoOutParam();
            MembersInfoInParam param = new MembersInfoInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as MembersInfoInParam;
                if (string.IsNullOrEmpty(param.user_id))
                {
                    result.code = "0";
                    result.desc = "请求参数不正确";

                    isFlag = false;
                }

                if (isFlag)
                {
                    if (CommonUtils.IsDisableUsers(param.user_id))
                    {
                        result.code = "0";
                        result.desc = "用户状态有问题，请联系管理员";

                        isFlag = false;
                    }
                }

                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetMembersInfo(param.user_id); 
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        result.data.analysis_reports = ds.Tables[0].Rows[0]["analysis_reports"].ToString();
                        result.data.branch_id = ds.Tables[0].Rows[0]["branch_id"].ToString();
                        result.data.branch_img = ds.Tables[0].Rows[0]["branch_img"].ToString();// SXT.Utility.FileServer.QueryFileUrl(ds.Tables[0].Rows[0]["branch_img"].ToString());
                        result.data.branch_int = ds.Tables[0].Rows[0]["branch_int"].ToString();
                        result.data.branch_name = ds.Tables[0].Rows[0]["branch_name"].ToString();
                        result.data.branch_peoples = ds.Tables[0].Rows[0]["branch_peoples"].ToString();
                        result.data.branch_rank = ds.Tables[0].Rows[0]["branch_rank"].ToString();
                        result.data.rank_num = ds.Tables[0].Rows[0]["rank_num"].ToString();
                        result.data.branch_sec = ds.Tables[0].Rows[0]["branch_sec"].ToString();
                        result.data.check_dept = ds.Tables[0].Rows[0]["check_dept"].ToString();
                        result.data.cname = ds.Tables[0].Rows[0]["cname"].ToString();
                        result.data.contact_addr = ds.Tables[0].Rows[0]["contact_addr"].ToString();
                        result.data.email = ds.Tables[0].Rows[0]["email"].ToString();
                        result.data.head_img = ds.Tables[0].Rows[0]["head_img"].ToString();// CommonUtils.GetSmallImg(SXT.Utility.FileServer.QueryFileUrl(ds.Tables[0].Rows[0]["head_img"].ToString()));
                        result.data.idcard = ds.Tables[0].Rows[0]["idcard"].ToString();
                        result.data.integral_rank = ds.Tables[0].Rows[0]["integral_rank"].ToString();
                        result.data.integral_total = ds.Tables[0].Rows[0]["integral_total"].ToString();
                        if(Convert.ToDecimal(ds.Tables[0].Rows[0]["is_can_test"]) >= 3)
                            result.data.is_can_test = "0";
                        else
                            result.data.is_can_test = "1";

                        if (result.data.head_img != null && result.data.head_img != "")
                            result.data.head_img = CommonUtils.GetFileUrl(result.data.head_img);

                        if (result.data.branch_img != null && result.data.branch_img != "")
                            result.data.branch_img = CommonUtils.GetFileUrl(result.data.branch_img);
                         
                        result.data.is_party_workers = ds.Tables[0].Rows[0]["is_party_workers"].ToString();
                        result.data.job = ds.Tables[0].Rows[0]["job"].ToString();
                        result.data.join_time = ds.Tables[0].Rows[0]["join_time"].ToString();
                        result.data.metting_signs = (Convert.ToInt32(ds.Tables[0].Rows[0]["metting_signs"]) + Convert.ToInt32(ds.Tables[0].Rows[0]["metting_signs_b"])
                            + Convert.ToInt32(ds.Tables[0].Rows[0]["metting_signs_c"])
                            - Convert.ToInt32(ds.Tables[0].Rows[0]["metting_signs_qd"]) - Convert.ToInt32(ds.Tables[0].Rows[0]["metting_signs_qd_b"])
                            - Convert.ToInt32(ds.Tables[0].Rows[0]["metting_signs_qd_c"])).ToString();
                        result.data.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
                        result.data.part_age = ds.Tables[0].Rows[0]["part_age"].ToString();
                        result.data.party_stu_url = ds.Tables[0].Rows[0]["party_stu_url"].ToString();
                        result.data.qq = ds.Tables[0].Rows[0]["qq"].ToString();
                        result.data.reg_dept = ds.Tables[0].Rows[0]["reg_dept"].ToString();
                        result.data.todos = ds.Tables[0].Rows[0]["todos"].ToString();
                        result.data.todosEx = ds.Tables[0].Rows[0]["todosEx"].ToString();
                        result.data.user_name = ds.Tables[0].Rows[0]["user_name"].ToString(); 
                    } 
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetMembersInfo", SerializeHelper.JsonSerializer<MembersInfoInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<MembersInfoInParam, MembersInfoOutParam>();
            else
                SafeProcessRequest<MembersInfoInParam, MembersInfoOutParam>();
        }
    }

    #region 请求参数
    public class MembersInfoInParam
    {
        /// <summary>
        /// 必填 用户ID
        /// </summary>
        public string user_id
        { get; set; } 
    }
    #endregion

    #region 结果参数
    public class MembersInfoOutParam
    {
        public MembersInfoOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new MembersInfo();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 个人信息
        /// </summary>
        public MembersInfo data
        { get; set; }
    } 

    /// <summary>
    /// 个人信息
    /// </summary>
    public class MembersInfo
    {
        /// <summary>
        /// 中文名
        /// </summary>
        public string cname
        { get; set; }

        /// <summary>
        /// 用户头像URL地址
        /// </summary>
        public string head_img
        { get; set; }

        /// <summary>
        /// 个人总积分
        /// </summary>
        public string integral_total
        { get; set; }

        /// <summary>
        ///	个人积分排名
        /// </summary>
        public string integral_rank
        { get; set; }

        /// <summary>
        /// 所在支部排名
        /// </summary>
        public string branch_rank
        { get; set; }

        /// <summary>
        /// 所在支部排名
        /// </summary>
        public string rank_num
        { get; set; }

        /// <summary>
        ///	待办数量
        /// </summary>
        public string todos
        { get; set; }

        /// <summary>
        ///	志愿者活动数量
        /// </summary>
        public string todosEx
        { get; set; }

        /// <summary>
        ///	会议签到数量 
        /// </summary>
        public string metting_signs
        { get; set; }

        /// <summary>
        ///	智能分析报表数量
        /// </summary>
        public string analysis_reports
        { get; set; }

        /// <summary>
        ///	用户名
        /// </summary>
        public string user_name
        { get; set; }

        /// <summary>
        /// 身份证号
        /// </summary>
        public string idcard
        { get; set; }

        /// <summary>
        /// 手机号码
        /// </summary>
        public string mobile
        { get; set; }

        /// <summary>
        /// 职务
        /// </summary>
        public string job
        { get; set; }

        /// <summary>
        /// 入党时间
        /// </summary>
        public string join_time
        { get; set; }

        /// <summary>
        /// 党龄
        /// </summary>
        public string part_age
        { get; set; }

        /// <summary>
        /// 登记组织
        /// </summary>
        public string check_dept
        { get; set; }

        /// <summary>
        /// 注册组织
        /// </summary>
        public string reg_dept
        { get; set; }

        /// <summary>
        /// 个人所在支部ID
        /// </summary>
        public string branch_id
        { get; set; }

        /// <summary>
        /// 个人所在支部名称
        /// </summary>
        public string branch_name
        { get; set; }

        /// <summary>
        /// 支部照片
        /// </summary>
        public string branch_img
        { get; set; }

        /// <summary>
        /// 组织人数
        /// </summary>
        public string branch_peoples
        { get; set; }

        /// <summary>
        /// 支部书记
        /// </summary>
        public string branch_sec
        { get; set; }

        /// <summary>
        /// 组织积分
        /// </summary>
        public string branch_int
        { get; set; } 

        ///// <summary>
        ///// 组织排名
        ///// </summary>
        //public string branch_rank
        //{ get; set; }

        /// <summary>
        /// 党员学习页面URL
        /// </summary>
        public string party_stu_url
        { get; set; }

        /// <summary>
        /// 党员今日是否还可参加考试
        /// </summary>
        public string is_can_test
        { get; set; }

        /// <summary>
        ///	电子邮箱
        /// </summary>
        public string email
        { get; set; }

        /// <summary>
        /// QQ
        /// </summary>
        public string qq
        { get; set; }

        /// <summary>
        /// 联系地址
        /// </summary>
        public string contact_addr
        { get; set; }

        /// <summary>
        /// 是否党务工作者
        /// </summary>
        public string is_party_workers
        { get; set; }
    }
    #endregion 
}